define([
  'jquery',
  'underscore',
  'backbone',
  'models/ContactModel',
  'collections/ContactCollection',
  'views/IndexView',
  'views/AboutView',
  'views/ContactView',
  'views/SeeContactsView',
  'views/PortfolioView'

], function($, _, Backbone,ContactModel, ContactCollection,IndexView, AboutView, ContactView, SeeContactsView, PortfolioView ) {
	var ItemRouter = Backbone.Router.extend({
		currentView: null,
		routes: {
			'index':'index',
			'about':'about',
			'contact':'contact',
			'seecontacts':'seecontacts',
			'portfolio':'portfolio'
		},
	    changeView: function(view) {
	        if ( null != this.currentView ) {
	          this.currentView.undelegateEvents();
	        }
	        this.currentView = view;
	        this.currentView.render();
	      },
	});
	
	var initialize = function(){
		var item_router = new ItemRouter;

		item_router.on('route:index', function() {
			console.log("llegue al on");
			item_router.changeView( new IndexView());
		});

		item_router.on('route:about', function() {
			item_router.changeView( new AboutView());
		});


		item_router.on('route:contact', function(id) {
			var modelContact = new ContactModel;
			item_router.changeView( new ContactView({model:modelContact, id:id}));
		});


		item_router.on('route:seecontacts', function() {
			var contactCollection = ContactCollection;
			item_router.changeView( new SeeContactsView({collection: contactCollection}));
			itemCollection.fetch();
		});
		

		item_router.on('route:portfolio',function(){
			item_router.changeView( new PortfolioView());
		});

		
		Backbone.history.start();
	};
	
	return { 
		initialize: initialize
	};
});